package com.wssnail.service.impl;

import com.wssnail.aes.AesException;
import com.wssnail.aes.SHA1;
import com.wssnail.service.VerifyUrlService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * @Author: yan
 * @CreateTime: 2022-09-23 13:27
 * @Description: TODO
 * @Version: 1.0
 */
@Service
public class VerifyUrlServiceImpl implements VerifyUrlService {

    @Value("${wssnail.wx.token}")
    private String token;

    public String verifyUrl(String msgSignature, String timeStamp, String nonce, String echoStr)
            throws AesException {
        String signature = SHA1.getSHA1(token, timeStamp, nonce);
        if (!signature.equals(msgSignature)) {
            throw new AesException(AesException.ValidateSignatureError);
        }
        return echoStr;
    }
}
